package com.dc.designPattern._23_specification.impl.step2;

import com.dc.designPattern._23_specification.impl.step2.spec.IUserSpecification;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Description: 用户实现接口
 * @author: gdc
 * @date: 2021/8/20
 * @version 1.0
 */
public class UserProvider implements IUserProvider {

    private List<User> userList;

    public UserProvider(List<User> userList) {
        this.userList = userList;
    }

    @Override
    public List<User> listByQuery(IUserSpecification userSpecification) {
        return userList.stream()
                .filter(userSpecification::isSatisfiedBy)               // 核心逻辑
                .collect(Collectors.toList());
    }
}
